{extend name='public/base' /}

{block name="content"}
<style>
    input[type=number] {
        -moz-appearance: textfield;
    }
    input[type=number]::-webkit-inner-spin-button,
    input[type=number]::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
</style>
<div class="layui-card">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">网站设置</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" value="{$data['name']}" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站域名</label>
                            <div class="layui-input-block">
                                <input type="text" name="domain" value="{$data['domain']}" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站LOGO</label>
                            <div class="layui-upload-drag" id="test10">
                                {if $data['icon']['src'] == '' }
                                <i class="layui-icon"></i>
                                <p>更换LOGO</p>
                                <div class="layui-hide" id="uploadDemoView">
                                    <img src="" alt="上传成功后渲染" style="max-width: 150px">
                                </div>
                                <input type="hidden" name="icon" value="">
                                {else /}
                                <i class="layui-icon" style="display: none"></i>
                                <p style="display: none">上传logo</p>
                                <div class="" id="uploadDemoView">
                                    <img src="{$data['icon']['src']}" alt="上传成功后渲染" style="max-width: 150px">
                                </div>
                                <input type="hidden" name="icon" value="{$data['icon']['path']}">
                                {/if}
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">最大文件上传</label>
                            <div class="layui-input-inline" style="width: 80px;">
                                <input type="number" name="upload_size" value="{$data['upload_size']}"
                                       class="layui-input">
                            </div>
                            <div class="layui-input-inline layui-input-company">MB</div>
                            <div class="layui-form-mid layui-word-aux">提示：1 M = 1024 KB</div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">网站描述</label>
                            <div class="layui-input-block">
                                <textarea name="desc" class="layui-textarea">{$data['desc']}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">版权信息</label>
                            <div class="layui-input-block">
                                <textarea name="copyright" class="layui-textarea">{$data['copyright']}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formInfo">确认保存</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    layui.use(['layer', 'upload', 'form'], function () {
        let $ = layui.$,
            form = layui.form,
            layer = layui.layer,
            upload = layui.upload;
        //拖拽上传
        upload.render({
            elem: '#test10',
            url: '/manage/system/upload/image',
            done: function (res) {
                if (res.code === 0) {
                    layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.data.src);
                    $('#test10 i').hide();
                    $('#test10 p').hide();
                    $("input[name='icon']").val(res.data.path);
                    console.log(res)
                } else {
                    layer.msg(res.message);
                }
            }
        });
        //表单提交
        form.on('submit(formInfo)', function (data) {
            $.ajax({
                type: "post",
                url: '/manage/system/website/update',
                data: data.field,
                success: function (data) {
                    // 根据服务端二次验证的结果进行跳转等操作
                    if (data.code !== 0) {
                        layer.msg(data.message, {icon: 5});
                    } else {
                        layer.msg('修改成功', {icon: 1});
                    }
                }
            });
        });
    });
</script>
{/block}